package com.LeeCode;

/**
 * 寻找比目标字母大的最小字母
 */

public class Code744 {
    public static void main(String[] args) {
        char[] letters = {'c', 'f', 'j' };
        char target = 'j';
        System.out.println(new Code744().nextGreatestLetter(letters, target));
    }

    public char nextGreatestLetter(char[] letters, char target) {
        int left = -1, right = letters.length, mid;
        while (left + 1 < right) {
            mid = left + (right - left) / 2;
            if (letters[mid] >= target + 1) {
                right = mid;
            } else {
                left = mid;
            }
        }
        if (right == letters.length) {
            return letters[0];
        }
        return letters[right];
    }
}
